Function.prototype.myCall = function (context = window, ...args) {
  if (typeof this !== "function") throw new Error("type error");

  const fn = Symbol("fn");
  context[fn] = this;

  let res = context[fn](...args);
  delete context[fn];

  return res;
};

Function.prototype.myApply = function (context = window, args) {
  if (typeof this !== "function") throw new Error("type error");

  const fn = Symbol("fn");
  context[fn] = this;

  let res = context[fn](...args);
  delete context[fn];

  return res;
};

Function.prototype.myBind = function (context, ...args) {
  if (typeof this !== "function") throw new Error("type error");
  let self = this;

  return function F() {
    if (this instanceof F) {
      return new self(...args, ...arguments);
    }
    return self.apply(context, [...args, ...arguments]);
  };
};

const foo = function (...args) {
  console.log(this.name, ...args);
  //   return {
  //     arr: [...args],
  //   };
};

const user = { name: "kaho" };

let func = foo.apply(user, [1, 2]);
console.log(func);
// func();
// console.log(res);
